/**
 *******************************************************************************
 * @file timer_driver.h
 * @author .ISS_AUTO (hudandan@issauto.com)
 * @date 2025-03-25  1. 添加 TIM2 定时计数 应用；
 *                   2. 添加 TIM3 PWM 输出应用；
 * @brief
 *
 * @copyright Copyright (c) 2025 ISSAUTO TECH Co., Ltd. All rights reserved.
 *
 *******************************************************************************
 */

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __TIMER_DRIVER_H
#define __TIMER_DRIVER_H

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* Exported types ------------------------------------------------------------*/
typedef struct {
    uint32_t previousCountValue;
    uint32_t timerOverflowInterruptCount; //!< 中断计数
    uint32_t Period; //!< 运算周期 (unit: ns)(range: 0 ~ 4,294,967,295)

} watch_timer_typedef_t;

typedef enum {
    WATCH_CHAN_0 = 0,
    // WATCH_CHAN_1,
    // .
    // .
    // .

    WATCH_CHAN_MAX_NUM,

} watch_timer_channel_e;

/* Exported macro ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* Period(us): 1000 / 2 = 500us */
// #define TIM2_ARR_VALUE                ((uint32_t)1000U)
// #define TIM2_PERIOD_US                ((uint32_t)2U)

/* Period(us): 2000 / 4 = 500us */
#define TIM2_ARR_VALUE                ((uint32_t)2000U)
#define TIM2_PERIOD_US                ((uint32_t)4U)


#define TIM3_PWM_CLK_FREQ             ((uint32_t)12000000U) //!< 时钟频率
#define TIM3_PWM_FREQ                 ((uint32_t)500U) //!< Hz


/* Exported variables --------------------------------------------------------*/
/* Exported functions --------------------------------------------------------*/
extern void Watch_TIMx_Callback(void);
extern void Watch_ClearInterval(watch_timer_channel_e chan);
extern watch_timer_typedef_t Watch_GetTimeInterval(watch_timer_channel_e chan);

void TIM2_Configuration(void);
void TIM3_PWM_Configuration(uint16_t pduty);


#endif /* __TIMER_DRIVER_H */

/* END OF FILE ---------------------------------------------------------------*/
